package com.allwees.bs.module.fms.rest;

import com.allwees.bs.core.modelbase.branch.EBranchType;
import com.allwees.bs.core.modelbase.exception.AuthException;
import com.allwees.bs.core.modelbase.exception.AuthExceptionEnum;
import com.allwees.bs.core.modelbase.vo.R;
import com.allwees.bs.module.core.rest.BoCrudApi;
import com.allwees.bs.module.fms.entity.PlatformWithdrawAccount;
import com.allwees.bs.module.fms.req.PlatformWithdrawAccountInfoReq;
import com.allwees.bs.module.fms.service.PlatformWithdrawAccountService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 平台提现账户操作
 *
 * @author yangylsky
 * @since 2019-12-30
 *
 */
@RestController
@RequestMapping("/backstage/api/fms/platform_withdraw_account")
public class PlatformWithdrawAccountApi extends BoCrudApi<PlatformWithdrawAccount, PlatformWithdrawAccountService> {
	@Override
	protected Object _doRetrieve(String uuid) {
		if(EBranchType.PLATFORM != getCurrentUser().getBranchType()) {
			throw new AuthException(AuthExceptionEnum.NO_AUTHORIZE);
		}
		return super._doRetrieve(uuid);
	}

    /**
     * 创建平台提现账户
     *
     * @param req
     * @return
     */
	@PostMapping("/create_account")
	public R createIndividualAcount(@RequestBody PlatformWithdrawAccountInfoReq req) {
		PlatformWithdrawAccount account = boService.createAccount(req);
        return R.ok("创建平台提现账户成功").put("uuid", account.getUuid());
	}

	/**
	 * 查询默认提现账户
	 *
	 * @return
	 */
	@GetMapping("default")
	public R findDefaultWithdrawAccount() {
		PlatformWithdrawAccount account = boService.findDefaultWithdrawAccount(getCurrentUser().checkPlatformUuid());
        return R.ok(account);
	}

	/**
	 * 查询默认提现账户
	 *
	 * @return
	 */
	@GetMapping("list")
	public R findAllWithdrawAccount() {
		List<PlatformWithdrawAccount> accounts = boService.findAllWithdrawAccount(getCurrentUser().getCurrentPlatformUuid());
        return R.ok(accounts);
	}
}
